var FileUtils = {
    packingUploadData: function (bizId, bizType) {
        return {bizId: bizId, bizType: bizType};
    },
    fileType: '',
    packingInitialPreview: function (obj) {
        obj = obj || [];
        let _info_img = [];
        let _info_img_config = [];
        for (const _car_file of obj) {
            console.log(_car_file);
            _info_img.push(root_url + _car_file.url);
            _info_img_config.push({
                key: _car_file.id,
                caption: _car_file.name + '.' + _car_file.fileType,
                size: _car_file.fileSize,
                url: root_url + '/system/files/remove'
            });
        }
        return {initialPreview: _info_img, initialPreviewConfig: _info_img_config};
    },
    fileinput: function (id, images, uploadData, _config) {
        let _initialPreview = FileUtils.packingInitialPreview(images || []);
        console.log(_initialPreview)
        let config = {
            // 'theme': 'explorer-fas',
            'uploadUrl': ctx + "common/upload",
            uploadExtraData: uploadData || {},
            'deleteUrl': ctx + "/system/files/remove",
            deleteExtraData: {},
            previewSettings: {
                image: {width: "100px", height: "100px"},
            },
            allowedFileExtensions: ['jpg', 'gif', 'png'],
            showCaption: true,//是否显示被选文件的简介
            showBrowse: true,//是否显示浏览按钮
            showPreview: false,//是否显示预览区域
            showRemove: false,//是否显示移除按钮
            showUpload: true,//是否显示上传按钮
            showCancel: false,//是否显示取消按钮
            showClose: false,//是否显示关闭按钮
            validateInitialCount: true,
            dropZoneEnabled: false,
            // showPreview:false,
            overwriteInitial: false,
            initialPreviewAsData: true,
            // minFileCount: 0, //表示允许同时上传的最大文件个数
            initialPreview: _initialPreview.initialPreview,
            initialPreviewConfig: _initialPreview.initialPreviewConfig
        };
        $.extend(true, config, _config);
        $("#" + id).fileinput(config);
    },
    fileuploaded: function (id, fn) {
        $("#" + id).on("fileuploaded", function (event, data, previewId, index) {
            if ($.isFunction(fn)) {
                fn(event, data, previewId, index);
            }
        });
    },
    filesuccessremove: function (id, fn) {
        $("#" + id).on("filesuccessremove", function (event, data, previewId, index) {
            if ($.isFunction(fn)) {
                fn(event, data, previewId, index);
            }
        });
    },
    delete: function (id) {
        $.modal.loading("正在处理中，请稍后...");
        // $.post(root_url + "/system/files/remove?key=" + id, {key: id}, function (data) {
        $.post(root_url + "/system/files/remove", {key: id}, function (data) {
            $('#id_fileinput_img' + id).remove();
            $.modal.closeLoading();
        });
    }
};
